package com.jacken.mars.commons.mq.base.delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @author wangqiang
 * @version 1.0
 * @date 2021/1/10 14:27
 * 延迟消息
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("delay-group-01");
        producer.setNamesrvAddr("114.55.146.111:9876");
        producer.start();


        for (int i = 0; i < 10; i++) {
            Message message = new Message("delay-topic", "delay-tag", "delay-message".getBytes());
            //设置消息延时时间
            message.setDelayTimeLevel(5);
            SendResult result = producer.send(message);
            System.out.println("发送 result:" + result);

        }

        producer.shutdown();

    }
}
